def get_one_complement_unsigned(num, bit_length):
    # 计算掩码
    mask = (1 << bit_length) - 1
    # 按位异或
    result = num ^ mask
    return result

# 测试
a = 10
bit_length = 8
b = get_one_complement_unsigned(a, bit_length)
print(f"原数: {a}={bin(a)}")
print(f"反码: {b}={bin(b)}")